<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>首页</title>
    <!-- 引入 echarts.js -->
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <script src="https://code.highcharts.com/modules/export-data.js"></script>
    <script src="https://code.highcharts.com/modules/accessibility.js"></script>

    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet"
          href="/plugins/bootstraptable/bootstrap-table-master/dist/bootstrap-table.min.css">
    <!-- 添加一些简单的 CSS 样式 -->
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin:60px;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            flex-wrap: wrap;
        }
        .chart-container {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            margin: 20px;
            padding: 20px;
            width: 450px;
            box-sizing: border-box; /* 使得容器宽度包括 padding 和 border */
        }
        .chart-title {
            text-align: center;
            font-size: 18px;
            margin-bottom: 10px;
        }
        #genderChart, #ageChart, #scoreChart, #ageChangeChart, #scoreChangeChart{
            width: 100%;
            height: 250px;
        }
        #tooltip {
            position: absolute;
            padding: 10px;
            background-color: rgba(50, 50, 50, 0.7);
            color: white;
            border-radius: 4px;
            pointer-events: none;
            display: none; /* 默认隐藏 */
        }
        .chart-legend {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .chart-legend li::before {
            content: "";
            display: inline-block;
            width: 12px;
            height: 12px;
            margin-right: 6px;
            border-radius: 50%;
        }
    </style>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <p class="navbar-text" style="font-size: 18px">学生后台管理系统</p>
        <ul class="nav nav-tabs" style="font-size: 18px">
            <li role="presentation" ><a href="/home/index">首页</a></li>
            <li role="presentation" ><a href="/students/list">学生信息管理</a></li>
            <li role="presentation"><a href="/stscore/list">学生成绩管理</a></li>
            <li role="presentation"><a href="/course/list">学生选课管理</a></li>
        </ul>
    </div>
</nav>

<div id="student-scores-chart" style="min-width: 435px; height: 400px; margin: 0 auto"></div>
<div id="student-score-chart" style="min-width: 435px; height: 400px; margin: 0 auto"></div>
<script>
    fetch('/webapi/stscore/list1')
        .then(response => response.json())
        .then(data => {
        console.log(data)
        // 提取学生姓名和每个科目的成绩数据
        const categories = data.data.map(student => student.name);
        const gaoshuScores = data.data.map(student => student.gaoshu);
        const xiandaiScores = data.data.map(student => student.xiandai);
        const jizuScores = data.data.map(student => student.jizu);

        // 创建学生成绩分布图表
        Highcharts.chart('student-scores-chart', {
            chart: {
                type: 'column'
            },
            title: {
                text: '学生成绩分布图表'
            },
            xAxis: {
                categories: categories,
                crosshair: true
            },
            yAxis: {
                min: 0,
                title: {
                    text: '成绩'
                }
            },
            tooltip: {
                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
                footerFormat: '</table>',
                shared: true,
                useHTML: true
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: [{
                name: '高数',
                data: gaoshuScores

            }, {
                name: '线代',
                data: xiandaiScores

            }, {
                name: '计组',
                data: jizuScores

            }]
        });
            // 创建学生成绩趋势折线图
            Highcharts.chart('student-score-chart', {
                chart: {
                    type: 'line'
                },
                title: {
                    text: '学生成绩趋势'
                },
                xAxis: {
                    categories: categories,
                    title: {
                        text: '学生姓名'
                    }
                },
                yAxis: {
                    title: {
                        text: '成绩'
                    }
                },
                series: [{
                    name: '高数',
                    data: gaoshuScores
                }, {
                    name: '线代',
                    data: xiandaiScores
                }, {
                    name: '计组',
                    data: jizuScores
                }]
            });
    });
</script>

<script src="/js/bootstrap.min.js"></script>
</body>
</html>